package com.gupaoedu.pattern.observer.event;

import java.lang.reflect.Method;

/**
 * 2019/9/28
 * created by chenpp
 */
public class Event {

    //事件源,事件是由什么发起的(被观察者)
    private Object source;
    //事件触发后通知的对象(观察者)
    private Object target;
    private Method callback;//监听消息后的回调方法
    private String eventType;//监听到的事件名称
    private Long time;//监听到事件的时间

    //之所以这样定义，是因为在addListener的时候需要告诉事件源，回调方法和通知的对象
    public Event(Object target,Method callback){
        this.target = target;
        this.callback = callback;
    }

    public Object getSource() {
        return source;
    }

    public void setSource(Object source) {
        this.source = source;
    }

    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }

    public Method getCallback() {
        return callback;
    }

    public void setCallback(Method callback) {
        this.callback = callback;
    }

    public String getEventName() {
        return eventType;
    }

    public Event setEventName(String eventName) {
        this.eventType = eventName;
        return this;
    }

    public Long getTime() {
        return time;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    @Override
    public String toString() {
        return "Event{" +
                "source=" + source +
                ",\n target=" + target +
                ",\n callback=" + callback +
                ",\n eventType='" + eventType + '\'' +
                ",\n time=" + time +
                '}';
    }
}
